	PRO PROFILES,dir,Nproc,time,PS=PS
; Compute profiles (uin,uotu,Bx,Jz) at the x-point
; time format example: '0010'
leer_input,dir,N,nu,eta,eps,delta,dt,nstep,nstg,nstdat,nstk,nstp
leer,dir,time,Nproc,a,f,b,u,jj,ww
if delta ne 0 then epse=eps*sqrt(delta)
if delta eq 0 then epse=100

x=2.*!pi*dindgen(N)/N & y=x & dx=x(1)
uupx=dblarr(N,N) & uupy=uupx
uuex=uupx & uuey=uupx
bbx=uupx & bby=uupx

fp=f+(eps*delta/sqrt(1+delta))*b
fe=f-(eps/sqrt(1+delta))*b
comcampos,fp,uupx,uupy,x,y ; Compute velocity field components
comcampos,fe,uuex,uuey,x,y ; Compute electron flow components
comcampos,a,bbx,bby,x,y; Compute magnetic field components
efield,dir,Nproc,long(time),eex,eey,eez ; Compute electric field components

upx=dblarr(N) & upy=upx 
uex=upx & uey=upx 
jz=upx 
bx=upx & by=upx & bz=upx 

upx=uupx(*,N/4-1) & uex=uuex(*,N/4-1)
upy=uupy(N/2-1,*) & uey=uuey(N/2-1,*)
jz=jj(N/2-1,*) & bz=b(N/2-1,*)
bx=bbx(N/2-1,*) & by=bby(N/2-1,*)
ex=eex(N/2-1,*) & ez=eez(N/2-1,*)
exby = (bx*ez-bz*ex)/(bx^2+by^2+bz^2)

;diff_uy = abs(upy-uey)
;dif_uy_1 = diff_uy(0:N/4-1)
;dif_uy_2 = diff_uy(N/4+1:N/2-1)
ind_max_uey = where(uey(0:N/2-1) eq max(uey(0:N/2-1)))
ind_min_uey = where(uey(0:N/2-1) eq min(uey(0:N/2-1)))
ymax = y(ind_max_uey)
ymin = y(ind_min_uey)
bxmax2 = bx(ind_max_uey)*bx(ind_max_uey) 
;ind_min_dif_uy_1 = where(dif_uy_1 eq min(dif_uy_1))
;ind_min_dif_uy_2= where(dif_uy_2 eq min(dif_uy_2))
ind_min_uex = where(uex(0:N/2-1) eq min(uex(0:N/2-1)))
ind_max_uex = where(uex(N/2-1:N-1) eq max(uex(N/2-1:N-1)))
;
maxux = max([max(uex),max(upx)]) & minux = abs(min([min(uex),min(upx)]))
maxuy = max([max(uey),max(upy)]) & minuy = abs(min([min(uey),min(upy)]))
;
print,'d_e (width)',abs(ymin-ymax)/2
print,'D_e (length)',abs(x(N/2-1+ind_max_uex)-x(ind_min_uex))/2
print,'Bx^2',bxmax2
print,'Max(uex)',max(uex),'  ','Max(upx)',max(upx)
print,'E (rec.rate)', (ymin-y(N/4-1))/(x(N/2-1+ind_max_uex)-x(N/2-1))

epse = 4*epse;*sqrt(1/delta)
eps = 4*eps;*sqrt(1/delta)
;
if not keyword_set(ps) then window,1,xs=700,ys=700
if keyword_set(ps) then begin
set_plot,'PS'
device,filename=dir+'profiles.eps',bits_per_pixel=8,/encapsulated,xs=24,ys=24
endif
!p.multi = [0,1,4]
plot,[0,2*!pi],[0,0],xr=[!pi/4,3*!pi/4],linestyle=1,xsty=1,ysty=1,xtit='y',ytit='Uin(y)',tit='The X-point',charsize=2.5,yr=[-1.1*minuy,1.1*maxuy]
oplot,[!pi/2+epse/2,!pi/2+epse/2],col=100,[-100,100],linestyle=2
oplot,[!pi/2-epse/2,!pi/2-epse/2],col=100,[-100,100],linestyle=2
oplot,[!pi/2+eps/2,!pi/2+eps/2],col=100,[-100,100],linestyle=5
oplot,[!pi/2-eps/2,!pi/2-eps/2],col=100,[-100,100],linestyle=5
;oplot,[ymax,ymax],col=100,[-100,100],linestyle=1
;oplot,[ymin,ymin],col=100,[-100,100],linestyle=1
oplot,y,uey,th=1
oplot,y,upy,th=3
oplot,y,exby,th=2
;oplot,[x(ind_min_dif_uy_1),x(ind_min_dif_uy_1)],[-100,100],col=100,linestyle=1
;oplot,[x(N/4+1+ind_min_dif_uy_2),x(N/4+1+ind_min_dif_uy_2)],[-100,100],col=100,linestyle=1

plot,[0,2*!pi],[0,0],linestyle=1,xr=[!pi/4,3*!pi/4],yr=[-1.1*abs(min(jz)),1.1*max(jz)],xsty=1,ysty=1,xtit='y',ytit='Jz(y)',charsize=2.5
oplot,[!pi/2+epse/2,!pi/2+epse/2],col=100,[-100,100],linestyle=2
oplot,[!pi/2-epse/2,!pi/2-epse/2],col=100,[-100,100],linestyle=2
oplot,[!pi/2+eps/2,!pi/2+eps/2],col=100,[-100,100],linestyle=5
oplot,[!pi/2-eps/2,!pi/2-eps/2],col=100,[-100,100],linestyle=5
;oplot,[ymax,ymax],col=100,[-100,100],linestyle=1
;oplot,[ymin,ymin],col=100,[-100,100],linestyle=1
oplot,y,jz
;oplot,[x(ind_min_dif_uy_1),x(ind_min_dif_uy_1)],[-100,100],col=100,linestyle1
;oplot,[x(N/4+1+ind_min_dif_uy_2),x(N/4+1+ind_min_dif_uy_2)],[-100,100],col=100,linestyle=1

plot,[0,2*!pi],[0,0],linestyle=1,xr=[!pi/4,3*!pi/4],yr=[-1.1*abs(min(bx)),1.1*max(bx)],xsty=1,ysty=1,xtit='y',ytit='Bx(y)',charsize=2.5
oplot,[!pi/2+epse/2,!pi/2+epse/2],col=100,[-100,100],linestyle=2
oplot,[!pi/2-epse/2,!pi/2-epse/2],col=100,[-100,100],linestyle=2
oplot,[!pi/2+eps/2,!pi/2+eps/2],col=100,[-100,100],linestyle=5
oplot,[!pi/2-eps/2,!pi/2-eps/2],col=100,[-100,100],linestyle=5
oplot,[ymax,ymax],col=100,[-100,100],linestyle=1
oplot,[ymin,ymin],col=100,[-100,100],linestyle=1
oplot,y,bx
;oplot,xmax,bxmax2^0.5,psym=2
;oplot,[x(ind_min_dif_uy_1),x(ind_min_dif_uy_1)],[-100,100],col=100,linestyle=1
;oplot,[x(N/4+1+ind_min_dif_uy_2),x(N/4+1+ind_min_dif_uy_2)],[-100,100],col=100,linestyle=1

plot,x,uex,xr=[0,2*!pi],yr=[-1.1*minux,1.1*maxux],xsty=1,ysty=1,xtit='x',ytit='Uout(x)',charsize=2.5
oplot,x,upx,th=3
oplot,[0,2*!pi],[0,0],col=100,linestyle=1
oplot,[x(ind_min_uex),x(ind_min_uex)],[-100,100],col=100,linestyle=1
oplot,[x(N/2-1+ind_max_uex),x(N/2-1+ind_max_uex)],[-100,100],col=100,linestyle=1

if keyword_set(ps) then begin
device,/close
set_plot,'X'
endif

if not keyword_set(ps) then window,2,xs=700,ys=700
if keyword_set(ps) then begin
set_plot,'PS'
device,filename=dir+'del.eps',bits_per_pixel=8,/encapsulated,xs=24,ys=24
endif
!p.multi = 0
plot,[0,2*!pi],[0,0],xr=[!pi/2-0.5,!pi/2+0.5],linestyle=1,xsty=1,ysty=1,xtit='y',ytit='Uin(y)',tit='The X-point',charsize=2.5,yr=[-1.6*minuy,1.6*maxuy]
oplot,[!pi/2+epse/2,!pi/2+epse/2],col=100,[-100,100],linestyle=2 ;dash
oplot,[!pi/2-epse/2,!pi/2-epse/2],col=100,[-100,100],linestyle=2 ;dash
oplot,[!pi/2+eps/2,!pi/2+eps/2],col=100,[-100,100],linestyle=5 ;long dash
oplot,[!pi/2-eps/2,!pi/2-eps/2],col=100,[-100,100],linestyle=5 ;long dash
oplot,y,uey,th=1
oplot,y,upy,th=3
oplot,y,exby,th=2

if keyword_set(ps) then begin
device,/close
set_plot,'X'
endif
end
